package com.androidnetframe.exception;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;

import com.androidnetframe.R;

import java.util.HashMap;

/**
 * @author 何强
 *         2015-12-15
 */
public class OverideLayout extends View {
    public HashMap<Integer, IdMap> idHashMap = new HashMap<Integer, IdMap>();
    /**
     * 没有标记起点
     */
    public static final String No_Start = "0";
    /**
     * 没有结束点
     */
    public static final String No_End = "0";

    public OverideLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.test);
        String failed = a.getString(R.styleable.test_ConnectFailed);
        if (!TextUtils.isEmpty(failed)) {//连接错误
            saveId(failed, TypeCode.ConnectFailed);
        }
        String loadding = a.getString(R.styleable.test_requestNetLoadding);
        if (!TextUtils.isEmpty(loadding)) {//加载loadding
            saveId(loadding, TypeCode.requestNetLoadding);
        }
        String noNet = a.getString(R.styleable.test_NoNet);
        if (!TextUtils.isEmpty(noNet)) {//
            saveId(noNet, TypeCode.NoNet);
        }
        //没有数据的时候的加载位置
        String noData = a.getString(R.styleable.test_NoData);
        if (!TextUtils.isEmpty(noData)) {//
            saveId(noData, TypeCode.NoData);
        }
        a.recycle();
    }

    public void saveId(String str, int type) {
        int indexOf = str.indexOf("-");
        String start = str.substring(0, indexOf);
        String end = str.substring(indexOf + 1);
        IdMap tmpMap = new IdMap();
        tmpMap.startId = start;
        tmpMap.endId = end;
        idHashMap.put(type, tmpMap);
    }

    public class IdMap {
        public String startId;
        public String endId;
    }
}
